<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>computed、watch、methods监听数据变化</title>
  <script src="./js/vue2.js"></script>
</head>
<body>
  <div id="app">
    {{fullName}}
    <div>{{age}}</div>
  </div>
</body>
</html>
<script>
  var app = new Vue({
    el:'#app',
    data:{
      age:20,
      firstName:'lafen',
      lastName:'...',

      // watch需要定义一个变量
      // fullName:'lafen',
    },
    // 计算属性存在缓存
    // computed:{
    //   fullName: function(){
    //     return this.firstName + ' ' + this.lastName;
    //   }
    // },
    // 计算属性的get和set
    computed: {
      fullName:{
        get:function(){
          return this.firstName + ' ' + this.lastName;
        },
        set:function(val){
          var arr = val.split(' ');
          this.firstName = arr[0];
          this.lastName = arr[1];
        }
      }
    }
    // 通过方法来监听数据变化
    // methods: {
    //   fullName: function(){
    //     return this.firstName + ' ' + this.lastName;
    //   }
    // },
    // 通过watch属性
    // watch: {
    //   firstName: function(){
    //     this.fullName = this.firstName + ' ' + this.lastName;
    //   },
    //   lastName: function(){
    //     this.fullName = this.firstName + ' ' + this.lastName;
    //   }
    // }
  });
</script>